package com.example.administrator.libraryclub;

import android.content.Context;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import android.widget.TextView;

import com.example.administrator.libraryclub.util.UtilsTool;
import com.fmblzf.library.popwindow.PopWindowEditText;
import com.fmblzf.library.text.TextViewBackColor;

public class MainActivity extends AppCompatActivity {

    private TextView tvTime;
    private TextViewBackColor tvbc;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initViews();
    }

    private void initViews() {
        tvTime = (TextView) this.findViewById(R.id.tv_time);
        long miliSeconds = 437830123;
        String time = UtilsTool.convertSecondToTimeStr(miliSeconds);
        tvTime.setText(time);
        tvbc = (TextViewBackColor) this.findViewById(R.id.tvbc_time_reduce);
        tvbc.setSeconds(miliSeconds / 1000);
        tvbc.setViewText(time);
        tvbc.start();
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();

        //noinspection SimplifiableIfStatement
        if (id == R.id.action_settings) {
            return true;
        }

//        TranslateAnimation
        return super.onOptionsItemSelected(item);
    }

    @Override
    protected void onDestroy() {
        if(tvbc!=null)
            tvbc.stop();
        super.onDestroy();
    }

    public void onAnimatorClick(View view){
        Intent intent = new Intent(MainActivity.this,AnimatorActivity.class);
        startActivity(intent);
    }

    public void onBtnClck(View view){

        InputMethodManager imm = (InputMethodManager) this.getSystemService(Context.INPUT_METHOD_SERVICE);
//        imm.showSoftInput(view,InputMethodManager.SHOW_FORCED);
        imm.showSoftInputFromInputMethod(view.getWindowToken(),0);


        PopWindowEditText popWindowEditText = new PopWindowEditText();
//        popWindowEditText.ShowKeyboard(this, view);
        popWindowEditText.showPopWindow(this,view);

//        Intent intent = new Intent(MainActivity.this,TableListViewActivity.class);
//        startActivity(intent);
    }
}
